#include <QCoreApplication>
#include <QStringList>
#include "mysqlmyhandler.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    MysqlMyHandler handler;
    Connect_Manager *conn_manager;
    class DBServInfo dbservinfo ={"localhost","root","root","test",3306,NULL,0};
    QString conn_name = "first_conntion_name";
    handler.initConn(dbservinfo.hostname,dbservinfo.username,dbservinfo.password,
                dbservinfo.dbname,dbservinfo.port,dbservinfo.socket,dbservinfo.clientflag,conn_name);
    handler.setDBConn();

#if 0
    const QString sqlstr = "select * from saletable;";
    handler.selectData(sqlstr);
    qDebug()<<"第一次query后的open状态值：" << handler.openState;

    const QString sqlstr2 = "select * from testtable;";
    handler.selectData(sqlstr2);
    bool ret=handler.selectData(sqlstr);
    qDebug()<<"查询执行完成状态："<<ret;
# endif

    //const QString multilstr3 = " create view viewtest3 AS select book_name from teststable where book_price<50;  select * from  view_test2; ";

   // handler.multilSqlStatemtSelect(multilstr3);
    QString strmultil = " select * from saletable;select * from testtable; SELECT * from runoob_transaction_test; SELECT * from runoob_transaction_test;";
    handler.multilSqlStatemtSelect(" select * from saletable;select * from saletable;  select * from saletable;  select * from saletable;");
    handler.selectData("SELECT * FROM testtable;");
    QString tablename = "saletable";
    QVariantMap  insertmap1;
    insertmap1.insert("book_id", 32);
    insertmap1.insert("sale_num", 90);
    insertmap1.insert("sale_price", 55);
    insertmap1.insert("sale_total", 88);
//   handler.insertData(tablename ,insertmap1);

    //测试删除指定表中的指定数据
    QString strdelete = "sale_price=32";

//    handler.selectData("SELECT * FROM saletable;");
//    handler.SqlStatementDelete(tablename,strdelete);
//    handler.selectData("SELECT * FROM saletable;");

    qDebug() << "********查看表的结构信息********" ;
    handler.printTableStruct(tablename);

    //测试更新
//    QString updatestr = "update test.saletable set sale_price=19  where book_id=22;";
//    handler.updateData(updatestr);

    handler.selectData("SELECT * FROM saletable;");


    qDebug() << "**************";
    handler.selectData(" SELECT book_name FROM testtable;");
    return a.exec();
}


